package cn.anecansaitin.inet.mixins;

import cn.anecansaitin.inet.TranslateHelper;
import mcjty.lib.varia.OrientationTools;
import mcjty.rftoolsbase.api.xnet.channels.Color;
import mcjty.rftoolsbase.api.xnet.channels.IConnectorSettings;
import mcjty.rftoolsbase.api.xnet.gui.IEditorGui;
import mcjty.rftoolsbase.api.xnet.helper.AbstractConnectorSettings;
import net.minecraft.core.Direction;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(AbstractConnectorSettings.class)
public abstract class ConnectorSettingsMixin implements IConnectorSettings {
    @Shadow
    private Color[] colors;
    @Final
    @Shadow
    private Direction side;
    @Shadow
    private Direction facingOverride;

    @Inject(method = "sideGui", at = @At("HEAD"), remap = false, cancellable = true)
    protected void mixin$sideGui(IEditorGui gui, CallbackInfoReturnable<IEditorGui> cir) {
        cir.setReturnValue(gui.choices("facing", TranslateHelper.getText("inet.controller.setting.button.side.tooltip"), this.facingOverride == null ? this.side : this.facingOverride, OrientationTools.DIRECTION_VALUES));
        cir.cancel();
    }

    @Inject(method = "colorsGui", at = @At("HEAD"), remap = false, cancellable = true)
    protected void mixin$colorsGui(IEditorGui gui, CallbackInfoReturnable<IEditorGui> cir) {
        cir.setReturnValue(gui.colors("color0", TranslateHelper.getText("inet.controller.setting.button.color.tooltip"), this.colors[0].getColor(), Color.COLORS).colors("color1", TranslateHelper.getText("inet.controller.setting.button.color.tooltip"), this.colors[1].getColor(), Color.COLORS).colors("color2", TranslateHelper.getText("inet.controller.setting.button.color.tooltip"), this.colors[2].getColor(), Color.COLORS).colors("color3", TranslateHelper.getText("inet.controller.setting.button.color.tooltip"), this.colors[3].getColor(), Color.COLORS));
        cir.cancel();
    }
}
